/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package QuanLyThuoc;

import GiaoDien.GiaoDienChinh;
import KiemTra.KiemTra;
import QuanLyDonViTinh.DonViTinh;
import QuanLyLoaiThuoc.LoaiThuoc;
import QuanLyNhaCungCap.NhaCungCap;
import QuanLyNhaCungCap.ThemNhaCungCap;
import java.awt.event.ItemEvent;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;

/**
 *
 * @author PhuongNga
 */
public class ThemThuoc extends javax.swing.JFrame {

    Vector vLay = new Vector();
    DanhSachThuoc dst = new DanhSachThuoc();
    LoaiThuoc lt = new LoaiThuoc();
    NhaCungCap ncc = new NhaCungCap();
    Thuoc t, t1 = new Thuoc();
    DonViTinh dvt = new DonViTinh();
    KiemTra    ktCTT = new KiemTra();

    public ThemThuoc() {
        try {
            setResizable(false);


            initComponents();
            vLay = NhaCungCap.layTenNhaCungCap();
            layTenNhaCungCap(vLay);

            vLay = LoaiThuoc.xemTenLoaiThuoc();
            layTenLoaiThuoc(vLay);

            vLay = Thuoc.xemThuoc();
            layTenThuoc(vLay);

            vLay = DonViTinh.xemDonViTinh();
            layDonViTinh(vLay);
        } catch (SQLException ex) {
            Logger.getLogger(ThemThuoc.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    //Lấy mã Loại thuốc
    public void layTenLoaiThuoc(Vector vLay) {
        Vector loaiThuoc = new Vector();
        loaiThuoc.addElement("---Chọn loại thuốc---");
        for (int i = 0; i < vLay.size(); i++) {
            lt = (LoaiThuoc) vLay.get(i);
            loaiThuoc.addElement(lt.getTenLoaiThuoc());
        }
        DefaultComboBoxModel modelLoaiThuoc = new DefaultComboBoxModel(loaiThuoc);
        cbLoaiThuoc.setModel(modelLoaiThuoc);
    }

    //Lấy tên nhà cung cấp
    public void layTenNhaCungCap(Vector vLay) {
        Vector nhaCungCap = new Vector();
        nhaCungCap.addElement("---Chọn Nhà cung cấp---");
        for (int i = 0; i < vLay.size(); i++) {
            ncc = (NhaCungCap) vLay.get(i);

            nhaCungCap.addElement(ncc.getTenNhaCungCap());
        }
        DefaultComboBoxModel modelNCC = new DefaultComboBoxModel(nhaCungCap);
        cbNhaCungCap.setModel(modelNCC);
    }
    //Lấy tên thuốc vào combobox thuốc

    public void layTenThuoc(Vector vLay) {
        Vector Thuoc = new Vector();
        Thuoc.addElement("---Chọn tên Thuốc---");
        for (int i = 0; i < vLay.size(); i++) {
            t = (Thuoc) vLay.get(i);
            Thuoc.addElement(t.getTenThuoc());
        }
        DefaultComboBoxModel modelThuoc = new DefaultComboBoxModel(Thuoc);
        cbTenThuoc.setModel(modelThuoc);
    }

    //Lấy đơn vị tính
    public void layDonViTinh(Vector vLay) {
        Vector donViTinh = new Vector();
        donViTinh.addElement("---Chọn Đơn vị tính---");
        for (int i = 0; i < vLay.size(); i++) {
            dvt = (DonViTinh) vLay.get(i);
            donViTinh.addElement(dvt.getTenDonViTinh());
        }
        DefaultComboBoxModel modeldvt = new DefaultComboBoxModel(donViTinh);
        cbTenDonViTinh.setModel(modeldvt);
    }

    //Kiểm tra tên thuốc có trùng hay không
    public boolean kiemTraTenThuoc() {
        boolean kt = true;
        int dem = 0;
        Vector thuoc = new Vector();
        try {
            thuoc = Thuoc.xemThuoc();
        } catch (SQLException ex) {
            Logger.getLogger(ThemThuoc.class.getName()).log(Level.SEVERE, null, ex);
        }
        for (int i = 0; i < thuoc.size(); i++) {
            t = (Thuoc) thuoc.get(i);
            if (txtTenThuoc.getText().toString().equals(t.getTenThuoc().toString())) {
                dem++;
            }
        }
        if (dem != 0) {
            int show = JOptionPane.showConfirmDialog(this, "Tên thuốc bạn vừa nhập  bị trùng " + dem + " giá trị.Bạn vẫn muốn lưu?", "Thông báo", JOptionPane.YES_NO_OPTION);
            if (show == JOptionPane.YES_OPTION) {
                kt = true;
            }
            if (show == JOptionPane.NO_OPTION) {
                kt = false;
            }
        }
        return kt;
    }
    //Phương thức thêm thuốc-------------------------------------------------------------------

    public void themThuoc() {
        if (txtTenThuoc.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "Bạn chưa nhập tên thuốc", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
            txtTenThuoc.requestFocus();
            return;
        } else if (cbLoaiThuoc.getSelectedItem().toString().equals("---Chọn loại thuốc---")) {
            JOptionPane.showMessageDialog(null, "Bạn chưa chọn loại thuốc");
            cbLoaiThuoc.requestFocus();
            return;
        } else if (cbNhaCungCap.getSelectedItem().toString().equals("---Chọn Nhà cung cấp---")) {
            JOptionPane.showMessageDialog(null, "Bạn chưa chọn nhà cung cấp");
            cbNhaCungCap.requestFocus();
            return;
        } else if (kiemTraTenThuoc() == false) {
            huy();
            return;
        }
        int kt = 0;
        t.setTenThuoc(txtTenThuoc.getText().trim());
        //Lấy mã loại thuốc
        Vector vLoaiThuoc = new Vector();
        try {
            vLoaiThuoc = LoaiThuoc.xemLoaiThuoc();
        } catch (SQLException ex) {
            Logger.getLogger(ThemThuoc.class.getName()).log(Level.SEVERE, null, ex);
        }
        for (int i = 0; i < vLoaiThuoc.size(); i++) {
            lt = (LoaiThuoc) vLoaiThuoc.get(i);
            //so sánh tên trùng thì lấy ra mã loại thuốc
            if (cbLoaiThuoc.getSelectedItem().toString().equals(lt.getTenLoaiThuoc().toString())) {
                t.setMaLoaiThuoc((int) lt.getMaLoaiThuoc());
            }
        }
        //Lấy mã nhà cung cấp
        Vector vNhaCungCap = new Vector();
        try {
            vNhaCungCap = NhaCungCap.xemNhaCungCap();
        } catch (SQLException ex) {
            Logger.getLogger(ThemThuoc.class.getName()).log(Level.SEVERE, null, ex);
        }
        for (int i = 0; i < vNhaCungCap.size(); i++) {
            ncc = (NhaCungCap) vNhaCungCap.get(i);
            if (cbNhaCungCap.getSelectedItem().toString().equals(ncc.getTenNhaCungCap().toString())) {
                t.setMaNhaCungCap((int) ncc.getMaNhaCungCap());
            }
        }
        try {
            kt = Thuoc.themThuoc(t);
            if (kt == 1) {
                JOptionPane.showMessageDialog(this, "Thêm mới thuốc thành công!", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
                 huy();
            } else {
                JOptionPane.showMessageDialog(this, "Thêm mới không thành công.Bạn hãy xem lại", "Thông báo", JOptionPane.ERROR_MESSAGE);
            }
        } catch (SQLException ex) {
            Logger.getLogger(ThemThuoc.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    
    //Kiểm tra chi tiết thuốc
    public boolean ktraCTT(){
        boolean ktctt = true;
         if (cbTenThuoc.getSelectedItem().toString().equals("---Chọn tên Thuốc---")) {
            JOptionPane.showMessageDialog(null, "Bạn chưa chọn tên thuốc");
            cbTenThuoc.requestFocus();
            ktctt = false;
         }else if (cbTenDonViTinh.getSelectedItem().toString().equals("---Chọn Đơn vị tính---")) {
            JOptionPane.showMessageDialog(null, "Bạn chưa chọn Đơn vị tính");
            cbTenDonViTinh.requestFocus();
            ktctt = false;
         }else if(!ktCTT.kiemTraSo(txtGia.getText().trim())){
             JOptionPane.showMessageDialog(null, "Giá bạn nhập chưa đúng.Nhập lại");
             txtGia.setText("");
             txtGia.requestFocus();
             ktctt = false;
         }else if(!ktCTT.kiemTraSo(txtSoLuong.getText().trim())){
             JOptionPane.showMessageDialog(null, "Số lượng bạn nhập chưa đúng.Nhập lại");
             txtSoLuong.setText("");
             txtSoLuong.requestFocus();
             ktctt = false;
         }else if(txtNam.equals("")){
             txtNam.setText("0");
         }else if(!ktCTT.kiemTraNam(txtNam.getText().trim())){
             JOptionPane.showMessageDialog(null, "Năm bạn nhập chưa đúng.Nhập lại");
             txtNam.setText("");
             txtNam.requestFocus();
             ktctt = false;
         }
         
        return ktctt;
        
}
    
    
    //Thêm bảng chi tiết thuốc
    public void themChiTietThuoc() {
        if(!ktraCTT()){
            return;
        }
        int kt = 0;

        //Lấy mã loại thuốc
        Vector vThuoc = new Vector();
        try {
            vThuoc = Thuoc.xemThuoc();
        } catch (SQLException ex) {
            Logger.getLogger(ThemThuoc.class.getName()).log(Level.SEVERE, null, ex);
        }
        for (int i = 0; i < vThuoc.size(); i++) {
            t1 = (Thuoc) vThuoc.get(i);
            if (cbTenThuoc.getSelectedItem().toString().equals(t1.getTenThuoc().toString())) {
                t.setMaThuoc((int) t1.getMaThuoc());
            }
        }

        //Lấy mã đơn vị tính
        Vector vDonViTinh = new Vector();
        try {
            vDonViTinh = DonViTinh.xemDonViTinh();
        } catch (SQLException ex) {
            Logger.getLogger(ThemThuoc.class.getName()).log(Level.SEVERE, null, ex);
        }
        for (int i = 0; i < vDonViTinh.size(); i++) {
            dvt = (DonViTinh) vDonViTinh.get(i);
            if (cbTenDonViTinh.getSelectedItem().toString().equals(dvt.getTenDonViTinh().toString())) {
                t.setMaDonViTinh(dvt.getMaDonViTinh().trim());
            }
        }
        float gia = Float.parseFloat(txtGia.getText().trim());
        t.setGia(gia);
        int soLuong = Integer.parseInt(txtSoLuong.getText().trim());
        t.setSoLuong(soLuong);
        t.setNguonGoc(txtNguonGoc.getText().trim());
        t.setCongDung(txtCongDung.getText().trim());
        //Lấy hạn sử dụng
        String hsd;
        hsd = (String) cbNgay.getSelectedItem() + "/" + cbThang.getSelectedItem() + "/" + txtNam.getText().trim();
        t.setHanDung(hsd);
        t.setHuongDanDung(txtHuongDanDung.getText().trim());

        try {
            kt = Thuoc.themChiTietThuoc(t);
            if (kt == 1) {
                JOptionPane.showMessageDialog(this, "Thêm mới chi tiết thuốc thành công!", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
                huyctt();
            } else {
                JOptionPane.showMessageDialog(this, "Thêm mới chi tiết không thành công.Tên thuốc và đơn vị tính đã tồn tại", "Thông báo", JOptionPane.ERROR_MESSAGE);
            }
        } catch (SQLException ex) {
            Logger.getLogger(ThemThuoc.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    //Hủy bảng thuốc
    public void huy() {
        try {
            txtTenThuoc.setText("");
            vLay = NhaCungCap.layTenNhaCungCap();
            layTenNhaCungCap(vLay);
            vLay = LoaiThuoc.xemTenLoaiThuoc();
            layTenLoaiThuoc(vLay);
            txtTenThuoc.requestFocus();
        } catch (SQLException ex) {
            Logger.getLogger(ThemThuoc.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    //hủy bảng chi tiết thuốc

    public void huyctt() {
        try {
            vLay = Thuoc.xemThuoc();
            layTenThuoc(vLay);
            vLay = DonViTinh.xemDonViTinh();
            layDonViTinh(vLay);
            txtGia.setText("");
            txtSoLuong.setText("");
            txtHuongDanDung.setText("");
            txtCongDung.setText("");
            txtNguonGoc.setText("");
            txtNam.setText("");
            cbNgay.setSelectedItem("1");
            cbThang.setSelectedItem("1");
            cbTenThuoc.requestFocus();

        } catch (SQLException ex) {
            Logger.getLogger(ThemThuoc.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDateChooserBeanInfo1 = new com.toedter.calendar.JDateChooserBeanInfo();
        jDateChooserBeanInfo2 = new com.toedter.calendar.JDateChooserBeanInfo();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        cbTenThuoc = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        cbTenDonViTinh = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        txtGia = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        txtSoLuong = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        txtNguonGoc = new javax.swing.JTextField();
        txtCongDung = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtHuongDanDung = new javax.swing.JTextArea();
        btThemDS = new javax.swing.JButton();
        btDongDS = new javax.swing.JButton();
        btHuyDS = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        cbNgay = new javax.swing.JComboBox();
        cbThang = new javax.swing.JComboBox();
        txtNam = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        txtTenThuoc = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        cbLoaiThuoc = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        cbNhaCungCap = new javax.swing.JComboBox();
        btThem = new javax.swing.JButton();
        btHuy = new javax.swing.JButton();
        btDong = new javax.swing.JButton();
        btThemNhaCungCapMoi = new javax.swing.JButton();
        jLabel13 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel5.setText("Tên thuốc");

        cbTenThuoc.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbTenThuoc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbTenThuocActionPerformed(evt);
            }
        });

        jLabel6.setText("Mã đơn vị tính");

        cbTenDonViTinh.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel7.setText("Giá");

        txtGia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtGiaActionPerformed(evt);
            }
        });

        jLabel1.setText("Số lượng");

        jLabel8.setText("Nguồn gốc");

        jLabel9.setText("Công dụng");

        jLabel11.setText("Hạn dùng");

        jLabel12.setText("Hướng dẫn dùng");

        txtNguonGoc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNguonGocActionPerformed(evt);
            }
        });

        txtCongDung.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCongDungActionPerformed(evt);
            }
        });

        txtHuongDanDung.setColumns(20);
        txtHuongDanDung.setRows(5);
        jScrollPane1.setViewportView(txtHuongDanDung);

        btThemDS.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/add 1.png"))); // NOI18N
        btThemDS.setText("Thêm");
        btThemDS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btThemDSActionPerformed(evt);
            }
        });

        btDongDS.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/exit.png"))); // NOI18N
        btDongDS.setText("Đóng");
        btDongDS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btDongDSActionPerformed(evt);
            }
        });

        btHuyDS.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/Delete.png"))); // NOI18N
        btHuyDS.setText("Hủy");
        btHuyDS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btHuyDSActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 36, Short.MAX_VALUE)
        );

        cbNgay.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));

        cbThang.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" }));

        jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/icons_pills.png"))); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(26, 26, 26)
                            .addComponent(cbTenThuoc, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                            .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                            .addGap(18, 18, 18)
                            .addComponent(txtCongDung, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                            .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txtGia, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel2Layout.createSequentialGroup()
                                    .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addGap(18, 18, 18))
                                .addGroup(jPanel2Layout.createSequentialGroup()
                                    .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, 92, Short.MAX_VALUE)
                                    .addGap(37, 37, 37)))
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(txtNguonGoc, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(jPanel2Layout.createSequentialGroup()
                                    .addComponent(cbNgay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(cbThang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(txtNam)))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(btThemDS, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(42, 42, 42)
                        .addComponent(btHuyDS, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel2Layout.createSequentialGroup()
                                    .addGap(17, 17, 17)
                                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                                        .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(37, 37, 37)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(50, 50, 50)
                        .addComponent(btDongDS)
                        .addGap(40, 40, 40)))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(txtSoLuong, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(cbTenDonViTinh, javax.swing.GroupLayout.Alignment.LEADING, 0, 178, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbTenThuoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(cbTenDonViTinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtGia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtSoLuong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(57, 57, 57)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtNguonGoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(39, 39, 39)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbNgay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbThang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtNam, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtCongDung, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btThemDS)
                            .addComponent(btDongDS)
                            .addComponent(btHuyDS)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(72, 72, 72)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(46, 46, 46))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
                                .addComponent(jLabel10)))))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Bảng chi tiết thuốc", jPanel2);

        jLabel2.setText("Tên thuốc");

        jLabel3.setText("Loại thuốc");

        jLabel4.setText("Nhà cung cấp");

        cbNhaCungCap.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        btThem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/add 1.png"))); // NOI18N
        btThem.setText("Thêm ");
        btThem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btThemActionPerformed(evt);
            }
        });

        btHuy.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/Delete.png"))); // NOI18N
        btHuy.setText("Hủy");
        btHuy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btHuyActionPerformed(evt);
            }
        });

        btDong.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/exit.png"))); // NOI18N
        btDong.setText("Đóng");
        btDong.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btDongActionPerformed(evt);
            }
        });

        btThemNhaCungCapMoi.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/add 1.png"))); // NOI18N
        btThemNhaCungCapMoi.setText("Thêm NCC mới");
        btThemNhaCungCapMoi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btThemNhaCungCapMoiActionPerformed(evt);
            }
        });

        jLabel13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Anh/icons_pills.png"))); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btThem, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(36, 36, 36)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(cbLoaiThuoc, 0, 184, Short.MAX_VALUE)
                                .addComponent(txtTenThuoc))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(btHuy, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(30, 30, 30)
                                .addComponent(btDong))
                            .addComponent(cbNhaCungCap, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(123, 123, 123)
                        .addComponent(btThemNhaCungCapMoi)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 85, Short.MAX_VALUE)
                .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(86, 86, 86))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtTenThuoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbLoaiThuoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(29, 29, 29)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbNhaCungCap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(29, 29, 29)
                        .addComponent(btThemNhaCungCapMoi))
                    .addComponent(jLabel13))
                .addGap(29, 29, 29)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btThem)
                    .addComponent(btHuy, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btDong, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(80, 80, 80))
        );

        jTabbedPane1.addTab("Bảng thuốc", jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1)
                .addGap(19, 19, 19))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtGiaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtGiaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtGiaActionPerformed

    private void txtNguonGocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNguonGocActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtNguonGocActionPerformed

    private void txtCongDungActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCongDungActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtCongDungActionPerformed

    private void cbTenThuocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbTenThuocActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cbTenThuocActionPerformed

    private void btThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btThemActionPerformed
        this.themThuoc();
        try {
            vLay = Thuoc.xemThuoc();//Hiển thị lên from chi tiết thuốc
            layTenThuoc(vLay);
        } catch (SQLException ex) {
            Logger.getLogger(ThemThuoc.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btThemActionPerformed

    private void btHuyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btHuyActionPerformed
        this.huy();
    }//GEN-LAST:event_btHuyActionPerformed

    private void btDongActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btDongActionPerformed
        int thongBao = JOptionPane.showConfirmDialog(null, "Bạn có muốn đóng thêm Thuốc?", "Thông báo", JOptionPane.YES_NO_OPTION);
        if (thongBao == JOptionPane.YES_OPTION) {
            this.dispose();
        }
    }//GEN-LAST:event_btDongActionPerformed

    private void btThemDSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btThemDSActionPerformed
        this.themChiTietThuoc();
    }//GEN-LAST:event_btThemDSActionPerformed

    private void btHuyDSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btHuyDSActionPerformed
        this.huyctt();
    }//GEN-LAST:event_btHuyDSActionPerformed

    private void btDongDSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btDongDSActionPerformed
        int thongBao = JOptionPane.showConfirmDialog(null, "Bạn có muốn đóng thêm chi tiết Thuốc?", "Thông báo", JOptionPane.YES_NO_OPTION);
        if (thongBao == JOptionPane.YES_OPTION) {
            this.dispose();
        }
    }//GEN-LAST:event_btDongDSActionPerformed

    private void btThemNhaCungCapMoiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btThemNhaCungCapMoiActionPerformed
        // TODO add your handling code here:
        new ThemNhaCungCap ().setVisible(true);
    }//GEN-LAST:event_btThemNhaCungCapMoiActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ThemThuoc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ThemThuoc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ThemThuoc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ThemThuoc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ThemThuoc().setVisible(true);
                
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btDong;
    private javax.swing.JButton btDongDS;
    private javax.swing.JButton btHuy;
    private javax.swing.JButton btHuyDS;
    private javax.swing.JButton btThem;
    private javax.swing.JButton btThemDS;
    private javax.swing.JButton btThemNhaCungCapMoi;
    private javax.swing.JComboBox cbLoaiThuoc;
    private javax.swing.JComboBox cbNgay;
    private javax.swing.JComboBox cbNhaCungCap;
    private javax.swing.JComboBox cbTenDonViTinh;
    private javax.swing.JComboBox cbTenThuoc;
    private javax.swing.JComboBox cbThang;
    private com.toedter.calendar.JDateChooserBeanInfo jDateChooserBeanInfo1;
    private com.toedter.calendar.JDateChooserBeanInfo jDateChooserBeanInfo2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField txtCongDung;
    private javax.swing.JTextField txtGia;
    private javax.swing.JTextArea txtHuongDanDung;
    private javax.swing.JTextField txtNam;
    private javax.swing.JTextField txtNguonGoc;
    private javax.swing.JTextField txtSoLuong;
    private javax.swing.JTextField txtTenThuoc;
    // End of variables declaration//GEN-END:variables
}
